import xlrd
import xlwt
from datetime import date,datetime
import os
import openpyxl
import sqlite3

data = sqlite3.connect('db.sqlite3')

print ("Opened database successfully")


c = data.cursor()

listinsheet = openpyxl.load_workbook(r'asset.xlsx')

datainlist = listinsheet.active  # 获取excel文件当前表格

data_truck = INSERT INTO virus_asset(
    id, Finish, Source, Document_No, Order_No, 
    Requisition_date, Materials, Department, 
    Requisitioner, Requisition_Num, Requisition_purpose, 
    Order_Time, Purchaser, Reason, Arrival_time1, Arrival_time2, 
    Actual_time1, Actual_Num1, Actual_time2, Actual_Num2, Actual_time3, 
    Actual_Num3, Unarrival_Num, Overdue, Overdue_time, Remarks, Supplier) 
    VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)  
for row in datainlist.iter_rows(min_row=2, max_col=27, max_row=datainlist.max_row):
    # 使excel各行数据成为迭代器
    cargo = [cell.value for cell in row]  # 敲黑板！！使每行中单元格成为迭代器
    c.execute(data_truck, cargo)  # 敲黑板！写入一行数据到数据库中表mylist
data.commit()
data.close()